using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace The_LarX
{
    /// <summary>
    /// Class for handling Cameras in 2D. Useful for side-scrolling games, or upper games like
    /// Age of Empires.
    /// </summary>
    public class Camera2D : Component
    {
        /// <summary>
        /// The Position of the Camera - 
        /// X and Y are the Position(Vector2)
        /// Z for Zoom
        /// </summary>        
        public Vector3 Position;

        /// <summary>
        /// World Matrix of the Camera, calculated every frame. Used for rendering.
        /// </summary>
        public Matrix World;

        /// <summary>
        /// Distance of the Camera(Z)
        /// </summary>
        public float Distance = 1;

        /// <summary>
        /// Camera Rotation in Degrees. This uses MathHelper to convert to Radians.
        /// </summary>
        public float DegreesRotation
        {
            get { return MathHelper.ToDegrees(RadiansRotation); }
            set
            {
                this.RadiansRotation = MathHelper.ToRadians(value);
            }
        }

        /// <summary>
        /// Camera Rotation in Radians
        /// </summary>
        public float RadiansRotation;

        /// <summary>
        /// Constructor Initializes the Camera, with Position X:0 Y:0 and Z(Zoom):1, and
        /// add it as a Service
        /// </summary>
        public Camera2D()
        {
            Position = new Vector3(0, 0, 1);
        }
        public Camera2D(GameScreen screen)
            : base(screen)
        {
            Position = new Vector3(0, 0, 1);
        }        
        

        public override void Update()
        {
            base.Update();

            World = MatrixUtil.CreateWorldMatrix(Matrix.CreateScale(Distance),
                Matrix.CreateRotationZ(RadiansRotation), 
                Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, 0)));
        }

        public override void SerializeData()
        {
            base.SerializeData();
        }
    }
}
